package com.ushine.web.base.controller;


import com.ushine.web.base.model.system.FunctionPermissionDO;
import com.ushine.web.base.service.IFunctionPermissionService;
import com.ushine.web.component.http.HttpResponseVO;
import com.ushine.web.log.annotation.SystemControllerLog;
import com.ushine.web.log.constant.LogConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yls
 * @Date: 2021/3/16 15:28
 * @Description: 权限管理控制器
 * @Version 1.0
 */
@RestController
@RequestMapping("system/permission")
@Api(tags = "基础模块-功能权限")
@Validated
public class FunctionPermissionController {

    @Resource
    private IFunctionPermissionService permissionService;

    @SystemControllerLog(operation = LogConstant.CREATE)
    @ApiOperation(value = "添加功能权限")
    @PostMapping("insertPermission")
    public HttpResponseVO<Object> insertPermission(@ApiParam(value = "功能权限", required = true) @RequestBody FunctionPermissionDO permission) {
        Boolean flag = permissionService.insertPermission(permission);
        if (Boolean.TRUE.equals(flag)) {
            return new HttpResponseVO<>().ok("添加成功！");
        } else {
            return new HttpResponseVO<>().error("添加失败！");
        }
    }

    @SystemControllerLog(operation = LogConstant.READ)
    @ApiOperation(value = "查询功能权限")
    @PostMapping("listAllPermissions")
    public HttpResponseVO<List<FunctionPermissionDO>> listAllPermissions() {
        List<FunctionPermissionDO> functionPermissions = permissionService.listAllPermissons();
        return new HttpResponseVO<List<FunctionPermissionDO>>().ok("", functionPermissions);
    }
}
